package com.demo.security.access.audit.prepost;

import com.demo.security.access.LogicAttribute;
import com.demo.security.access.audit.AuditModel;

/**
 * 前置调用审计属性
 * 
 * @author ryuu.kk
 */
public class PreInvocationAuditAttribute implements PreAuditAttribute {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 4006179862072416707L;
	/**
	 * 审计模型
	 */
	private final AuditModel audit;
	public PreInvocationAuditAttribute(int level, String code, String info) {
		audit = new AuditModel(level, code, info);
	}

	@Override
	public String getAttribute() {
		return audit.toString();
	}
    public int hashCode() {
        return super.hashCode();
    }

    public String toString() {
        return "PostInvocationAuditAttribute["
				+ (audit == null ? "-" : "Levle:" + audit.getLevel() 
				+ " Code:" + audit.getCode() 
				+ " Info:" + audit.getInfo())
				+ "];";
    }
    
	public boolean equals(Object obj) {
		if (obj instanceof LogicAttribute) {
			LogicAttribute attr = (LogicAttribute) obj;
			return this.audit.equals(attr.getAttribute());
		}
		return false;
	}

	@Override
	public AuditModel getAuditModel() {
		return audit;
	}
}
